import java.io.*;
import java.util.Scanner;

public class StringScanner2 {
  public static void main(String[] args) throws IOException{
       FileInputStream instream = new FileInputStream("grades.txt");
       Scanner fileScanner = new Scanner(instream);

       FileOutputStream outstream = new FileOutputStream("results.txt");
       PrintWriter pwriter = new PrintWriter(outstream);

      String line, name1, name2;
      int id, count;
      double sum, average;
      Scanner stringScanner = null;

      pwriter.printf("%9s%20s%15s%n", "ID#", "Name", "Average");
      while(fileScanner.hasNextLine()){
           sum = 0;
           count = 0;
           line = fileScanner.nextLine();
           stringScanner = new Scanner(line);
           id = stringScanner.nextInt();
           name1 = stringScanner.next();
           name2 = stringScanner.next();
           while(stringScanner.hasNextDouble()){
               sum += stringScanner.nextDouble();
               count++;
           }

           average = sum / count;
           pwriter.printf("%9d%20s%15.1f%n", id, name1 + " " + name2, average);
     }

      fileScanner.close();
      stringScanner.close();
      instream.close();
      pwriter.close();

      System.out.println("Output file results.txt created . . .");
  }
}